package com.industrial.operation.controller;

import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;

import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationKnowledgeLabel;
import com.industrial.operation.service.IOperationKnowledgeLabelService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 知识标签管理Controller
 * 
 * @author Zhou_S
 * @date 2024-02-20
 */
@RestController
@RequestMapping("/label")
public class OperationKnowledgeLabelController extends BaseController
{
    @Autowired
    private IOperationKnowledgeLabelService operationKnowledgeLabelService;

    /**
     * 查询知识标签管理列表
     */
    @RequiresPermissions("operation:label:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationKnowledgeLabel operationKnowledgeLabel)
    {
        startPage();
        List<OperationKnowledgeLabel> list = operationKnowledgeLabelService.selectOperationKnowledgeLabelList(operationKnowledgeLabel);
        return getDataTable(list);
    }

    /**
     * 导出知识标签管理列表
     */
    @RequiresPermissions("operation:label:export")
    @Log(title = "知识标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationKnowledgeLabel operationKnowledgeLabel)
    {
        List<OperationKnowledgeLabel> list = operationKnowledgeLabelService.selectOperationKnowledgeLabelList(operationKnowledgeLabel);
        ExcelUtil<OperationKnowledgeLabel> util = new ExcelUtil<OperationKnowledgeLabel>(OperationKnowledgeLabel.class);
        util.exportExcel(response, list, "知识标签管理数据");
    }

    /**
     * 获取知识标签管理详细信息
     */
    @RequiresPermissions("operation:label:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationKnowledgeLabelService.selectOperationKnowledgeLabelByBaseId(baseId));
    }

    /**
     * 新增知识标签管理
     */
    @RequiresPermissions("operation:label:add")
    @Log(title = "知识标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationKnowledgeLabel operationKnowledgeLabel)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> roles= loginUser.getRoles();
         if(roles.contains("q_01_001")){
          return  warn("无此添加权限!");
        }else{
             return toAjax(operationKnowledgeLabelService.insertOperationKnowledgeLabel(operationKnowledgeLabel));
         }

    }

    /**
     * 修改知识标签管理
     */
    @RequiresPermissions("operation:label:edit")
    @Log(title = "知识标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationKnowledgeLabel operationKnowledgeLabel)
    {
        return toAjax(operationKnowledgeLabelService.updateOperationKnowledgeLabel(operationKnowledgeLabel));
    }

    /**
     * 删除知识标签管理
     */
    @RequiresPermissions("operation:label:remove")
    @Log(title = "知识标签管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationKnowledgeLabelService.deleteOperationKnowledgeLabelByBaseIds(baseIds));
    }
}
